from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field

class Skill(BaseModel):
    id: str = Field(..., description="技能id")
    name: str = Field(..., description="技能名称") 
    description: str = Field(default='', description="技能描述")
    tags: List[str] = Field(default=[], description="技能标签")
    examples: List[str] = Field(default=[], description="输入示例")

class NodeConfig(BaseModel):
    name: str = Field(..., description="节点名称")
    desc: str = Field(default='', description="节点功能描述")
    conf: str = Field(default='', description="节点初始化配置文件")
    instance: str = Field(default='', description="节点实例class")
    type: str = Field(default='', description="节点类型")

class EdgeCondition(BaseModel):
    name: str = Field(..., description="目的节点名称")
    condition: str = Field(default='', description="节点路由条件")
    parallel: Dict[str, Any] = Field(default={}, description="并发执行配置")

class GraphConfig(BaseModel):
    node: List[NodeConfig] = Field(..., description="节点列表")
    edge: Dict[str, List[EdgeCondition]] = Field(..., description="边列表")

class MemoryConfig(BaseModel):
    enable_read: bool = Field(default=False, description="是否读取记忆")
    enable_write: bool = Field(default=False, description="是否更新记忆")
    short_term_ttl: int = Field(default=1800, description="短期记忆ttl")
    long_term_ttl: int = Field(default=0, description="长期记忆ttl")
    prompt: str = Field(default='', description="")

class ShortTermConfig(BaseModel):
    read: bool = Field(default=False, description="是否读取记忆")
    write: bool = Field(default=False, description="是否更新记忆")
    ttl: int = Field(default=604800, description="短期记忆ttl")
    strategy: str = Field(default='', description="短期记忆生成策略")

class LongTermConfig(BaseModel):
    read: bool = Field(default=False, description="是否读取记忆")
    write: bool = Field(default=False, description="是否更新记忆")
    ttl: int = Field(default=0, description="长期记忆ttl")
    strategy: str = Field(default='', description="长期记忆生成策略")

class ModelConfig(BaseModel):
    base_url: str = Field(default='', description="openai兼容大模型api baseurl")
    api_key: str = Field(default='', description="openai兼容大模型api apikey")
    model: str  = Field(default='', description="model name")

class MemoryConfig(BaseModel):
    short_term: ShortTermConfig = Field(default=ShortTermConfig(), description="短期记忆配置")
    long_term: LongTermConfig = Field(default=LongTermConfig(), description="长期记忆配置")
    model: ModelConfig = Field(default=ModelConfig(), description="模型配置")

class AgentConfig(BaseModel):
    name: str = Field(..., description="agent名称")
    desc: str = Field(default='', description="agent描述")
    version: str = Field(default='1.0', description="agent版本")
    skills: List[Skill] = Field(default=[], description="agent技能列表")
    memory: MemoryConfig = Field(default=MemoryConfig(), description="agent记忆配置")
    graph: GraphConfig = Field(..., description="agent名称")